﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeHouse.Server.Dto;

namespace LeHouse.Server.Dal
{
    /// <summary>
    /// 询价记录表DAL操作层
    /// </summary>
    public class Collateral_InquiryRecordDAL : GenericBaseDAL<Collateral_InquiryRecord>
    {

        /// <summary>
        /// 根据报告号去查询记录表是否有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int count(string P_ReportNumber)
        {
            int C_projectcount;
            string sql = @"select count(T_Date) from Collateral_InquiryRecord  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    C_projectcount = Convert.ToInt32(cmd.ExecuteScalar());
                }
                return C_projectcount;
            }
        }
        /// <summary>
        /// 根据报告号去查询询价记录表的信息
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public List<Collateral_InquiryRecord> Community(string P_ReportNumber)
        {
            List<Collateral_InquiryRecord> list = new List<Collateral_InquiryRecord>();
            string sql = @"select * from Collateral_InquiryRecord  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {

                        while (reader.Read())
                        {
                            Collateral_InquiryRecord munity = new Collateral_InquiryRecord();
                            munity.T_InquiryRecordID = Convert.ToInt32(reader["T_InquiryRecordID"]);
                            munity.T_Iname = reader["T_Iname"].ToString();
                            munity.T_ReportNumber = reader["T_ReportNumber"].ToString();
                            munity.T_Date = Convert.ToDateTime(reader["T_Date"]);
                            list.Add(munity);
                        }
                        return list;
                    }
                    finally
                    {
                        reader.Close();
                    }
                }

            }
        }

        public List<Collateral_InquiryRecord> Community(string P_ReportNumber, out Collateral_InquiryRecord tp)
        {
            tp = gett_proposal(P_ReportNumber);
            List<Collateral_InquiryRecord> list = new List<Collateral_InquiryRecord>();
            string sqlt_InquiryRecord = @"select * from Collateral_InquiryRecord  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sqlt_InquiryRecord;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            Collateral_InquiryRecord munity = new Collateral_InquiryRecord();
                            munity.T_InquiryRecordID = Convert.ToInt32(reader["T_InquiryRecordID"]);
                            munity.T_Iname = reader["T_Iname"].ToString();
                            munity.T_ReportNumber = reader["T_ReportNumber"].ToString();
                            munity.T_Date = Convert.ToDateTime(reader["T_Date"]);
                            list.Add(munity);
                        }
                        return list;
                    }
                    finally
                    {
                        reader.Close();
                    }
         

                }

            }
        }

        public Collateral_InquiryRecord gett_proposal(string P_ReportNumber)
        {
            Collateral_InquiryRecord munity = new Collateral_InquiryRecord();
            string sqlt_proposal = @"select * from Collateral_InquiryRecord  where T_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sqlt_proposal;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            munity.T_InquiryRecordID = Convert.ToInt32(reader["P_pid"]);
                         //   munity. = reader["P_proposal"].ToString();
                            munity.T_ReportNumber = reader["P_ReportNumber"].ToString();
                            munity.T_Date = Convert.ToDateTime(reader["P_date"]);

                        }
                        return munity;
                    }
                    finally
                    {
                        reader.Close();
                    }


                }

            }
        }
    }
}
